package com.ddwl.shop.service;

import com.ddwl.common.feign.api.GoodsApi;
import com.ddwl.common.util.BeanConverUtils;
import com.ddwl.schema.bo.shop.ShopRateBo;
import com.ddwl.shop.dao.ShopRateDao;
import com.ddwl.shop.dao.model.ShopRate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @Author hemiaojun
 * @Date 2021/7/1 15:56
 */
@Service
public class ShopRateService {


    @Resource
    private ShopRateDao shopRateDao;
    @Resource
    private GoodsApi goodsApi;


    @Transactional(rollbackFor = Exception.class)
    public void rate(ShopRateBo bo) {
        ShopRate entity = BeanConverUtils.convertBean(bo, ShopRate.class);
        bo.getItemRateBoList().forEach(itemRateBo -> {
            itemRateBo.setShopId(bo.getShopId());
            itemRateBo.setUserId(bo.getUserId());
            itemRateBo.setNickname(bo.getNickname());
        });
        shopRateDao.insert(entity);
        goodsApi.itemRate(bo.getItemRateBoList());
    }



}
